//package com.websocket_client;
//
//import org.java_websocket.client.WebSocketClient;
//import org.java_websocket.drafts.Draft;
//
//import javax.net.ssl.*;
//import java.net.Socket;
//import java.net.URI;
//import java.security.cert.CertificateException;
//import java.security.cert.X509Certificate;
//
///**
// * 构建SSLWebSocket客户端，忽略证书
// */
//public abstract class SSLWebSocketClient extends WebSocketClient {
//
//    //构造方法
//    public SSLWebSocketClient(URI serverURI, String message) {
//        super(serverURI);
//        if (serverURI.toString().contains("wss://")) {
//            trustAllHosts(this);
//            this.send(message);
//        }
//    }
//
//    public SSLWebSocketClient(URI serverURI, Draft draft) {
//        super(serverURI, draft);
//        if (serverURI.toString().contains("wss://"))
//            trustAllHosts(this);
//    }
//
//    /**
//     * 忽略证书
//     *
//     * @paramclient
//     */
//    void trustAllHosts(com.hikvision.modules.websocket.SSLWebSocketClient client) {
//        TrustManager[] trustAllCerts = new TrustManager[]{new X509ExtendedTrustManager() {
//            @Override
//            public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
//
//            }
//
//            @Override
//            public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
//
//            }
//
//            @Override
//            public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
//
//            }
//
//            @Override
//            public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
//
//            }
//
//            public X509Certificate[] getAcceptedIssuers() {
////                return new java.security.cert.X509Certificate[]{};
////                System.out.println("getAcceptedIssuers");
//                return null;
//            }
//
//            @Override
//            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
//                System.out.println("checkClientTrusted");
//            }
//
//            @Override
//            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
//                System.out.println("checkServerTrusted");
//            }
//        }};
//
//        try {
//
//            SSLContext ssl = SSLContext.getInstance("SSL");
//            ssl.init(null, trustAllCerts, new java.security.SecureRandom());
//
//            SSLSocketFactory socketFactory = ssl.getSocketFactory();
//            this.setSocketFactory(socketFactory);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}